Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 Search this book:
Previous | Table of Contents | Next
TIP: What About Me? You can use the Me keyword to refer to the current form. In other words, Me always refers to the form containing the code. As an example of a multiple form project, we will use two of the software components we have already developed: the Calculator and the Baby Editor. Start Visual Basic and create a new Standard EXE project. Add a control array of three Command Buttons to the form, and assign Caption properties as follows:
Button Index | Caption
--- | ---
0 | Editor
1 | Calculator
2 | Exit
Next, select the Add Form command on the Project menu. In the dialog box, click on the Existing tab and locate the Calculator form we created earlier, adding it to the project. Repeat to add the Baby Editor form as well. Add the code in Listing 11.17 to the Command Button’s Click event procedure. Save the project, using the name MultiForm for both the form and the project. When you run the program, you will first see a form with the three Command Buttons. Click on the Editor button and the Baby Editor appears; click on the Calculator button and the calculator appears. Click on either button again and the corresponding form disappears. When all three forms are displayed (as shown in Figure 11.7), you can switch among forms, move them around the screen, minimize them, and so on. Click on Quit to close all. Figure 11.7 The multiple form demonstration program. Listing 11.17 The Command Button’s Click event procedure.
    Private Sub Command1_Click(Index As Integer)

    Select Case Index
        Case 0:
            If frmBabyEditor.Visible = False Then
                frmBabyEditor.Show
            Else
                frmBabyEditor.Hide
            End If
        Case 1:
            If frmCalculator.Visible = False Then
                frmCalculator.Show
            Else
                frmCalculator.Hide
            End If
        Case 2:
            End
    End Select

    End Sub
Figuring out how the code works is easy. For each form, the code first checks its Visible property to see if the form is already displayed. If Visible is False, the Show method is used to display the form. If Visible is True, Hide is used to close the form. In this project, the startup form remains visible when another form is displayed. This is not always desirable, of course, and you can use the Hide method to close the first form at the same time you are using Show to display the second form. Note also that the three forms in the project are independent of each other—no “master” form contains the others, as is the case with many Windows applications. This effect is obtained with a so-called multiple document interface project, which we will explore in Chapter 22. ### Additional Text Processing We have learned a lot about working with text in this chapter, but Visual Basic offers even more. In particular, Visual Basic’s collection of built-in functions provides a wide range of useful text handling operations. You can, for example, locate one string within another, change capitalization, extract parts of strings, and apply specific formatting. Table 11.4 includes a brief listing of what’s available; I leave it to you to locate the details in the Visual Basic Help system. Table 11.4 Visual Basic’s string processing functions.
Action | Keyword
--- | ---
Compare two strings | StrComp
Convert a string to lowercase or uppercase | LCase, UCase
Create a string of a repeating character | Space, String
Find the length of a string | Len
Format a string | Format
Justify a string | LSet, Rset
Find one string in another | InStr, InstrRev
Extract part of a string | Mid function, Left, Right
Insert one string within another | Mid statement
Replace parts of strings | Replace
Trim leading and/or trailing spaces | LTrim, RTrim, Trim
Set string comparison rules | Option Compare
Work with ASCII and ANSI values | Asc, Chr
Convert strings | StrConv
Process arrays of strings | Filter, Join, Split
Previous | Table of Contents | Next

| Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain